home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
UTILITY
/
BANDOG.ARJ
/
ROT13.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-05
|
856b
|
44 lines
#include <stdio.h>
main( int argc, char *argv[] )
{
FILE *stream;
int i;
/* Check for proper command line syntax */
if( argc == 1 ) {
puts( "Command syntax is:\n\nROT13 infile [> outfile]" );
exit( 1 );
}
else {
/* Open file for binary input */
if( ( stream = fopen( argv[1], "rb" ) ) == NULL ) {
puts( "Can't open file" );
exit( 1 );
}
}
/* Encrypt/decrypt entire file */
while( !feof( stream ) ) {
i = fgetc( stream );
/* Rotate letters A-M up */
if( ( i >= 'A' && i <= 'M' ) || ( i >= 'a' && i <= 'm' ) )
i += 13;
else {
/* Rotate letters N-Z down */
if( ( i >= 'N' && i <= 'Z' ) || ( i >= 'n' && i <= 'z' ) )
i += 13;
}
/* Print character */
putchar( i );
}
/* Close file */
fclose( stream );
/* Return to DOS with no error code */
exit( 0 );
}